package a07_二叉树;

/**
 * <p>
 * a09_二叉树的最小深度复习3
 * </p>
 *
 * @author flyduck
 * @since 2025/4/8
 */
public class a09_二叉树的最小深度复习3 {
    public int minDepth(TreeNode root) {
        if (root == null) {
            return 0;
        }

        int leftDepth = minDepth(root.left);

        int rightDepth = minDepth(root.right);
        if (leftDepth == 0) {
            return rightDepth + 1;
        }
        if (rightDepth == 0) {
            return leftDepth + 1;
        }
        return Math.min(leftDepth, rightDepth) + 1;
    }
}
